import { Body, Controller, Inject, Post } from "@midwayjs/core";
import { EmailService } from "../service/email.service";
import { RespInfo } from "../types/common.type";
import { EmailDTO } from "../dto/common";
import { CaptchaService } from "@midwayjs/captcha";


@Controller('/email')
export class EmailController {

  @Inject()
  emailService: EmailService;

  @Inject()
  captchaService: CaptchaService;

  @Post('/register/code')
  async sendRegisterCode(@Body() body: EmailDTO): Promise<RespInfo> {
    const { text } = await this.captchaService.text();
    return await this.emailService.sendRegisterCode(body.email, text)
  }

  @Post('/forgotpassword/code')
  async sendForgotPasswordCode(@Body() body: EmailDTO): Promise<RespInfo> {
    const { text } = await this.captchaService.text();
    return await this.emailService.sendForgotPasswordCode(body.email, text)
  }

}